package com.yidu.best.systemManagement.roleManagement.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yidu.best.systemManagement.roleManagement.dao.RoleDao;
import com.yidu.best.systemManagement.roleManagement.domain.Role;
import com.yidu.best.systemManagement.roleManagement.domain.RoleVo;
import com.yidu.best.systemManagement.roleManagement.service.RoleService;
import com.yidu.best.systemManagement.roleManagement.util.IDUtil;


@Service
public class RoleServiceImpl implements RoleService {
	@Autowired
	private RoleDao roleDao;
	
	@Override
	public Map<String, Object> findRole(RoleVo roleVo) {
		
		int count = roleDao.findCountRole(roleVo);
		int page = (roleVo.getPage()-1)*roleVo.getLimit();
		roleVo.setPage(page);
		
		List<Role> roleList = roleDao.findRole(roleVo);
		
		Map<String, Object> map = new HashMap<String ,Object>();
		
		map.put("data", roleList);
		
		map.put("code", 0);
		
		map.put("count", count);
		
		return map;
	}

	@Override
	public int addRole(Role role) {
		role.setRoleId(IDUtil.getUUID());
		role.setRoleable(1);
		role.setUserable(1);
		int addRole = roleDao.addRole(role);
		return addRole;
	}

	@Override
	public int updateRole(Role role) {
		return roleDao.updateRole(role);
	}

	@Override
	public int deleteRole(String roleId) {
		return roleDao.deleteRole(roleId);
	}

}
